<template>
	<view class="invite">
		<image :src="url" mode="widthFix" style="width: 70vw;"></image>
		<view class="btn" @click="saveImg">
			点击保存二维码
		</view>
	</view>
</template>

<script>
	import {
		myCode,

	} from "@/request/api/goods.js"
	export default {
		data() {
			return {
				userInfo: {},
				url: ""
			}
		},
		onLoad() {
			this.userInfo = uni.getStorageSync("userInfo")
			myCode(this.userInfo.id).then(res => {
				this.url = 'https://ba.fuliaoxx.com/' + res.data.codeUrl
			})
		},
		methods: {
			saveImg() {
				uni.downloadFile({
					url: this.url,
					success: function(res) {

						wx.saveImageToPhotosAlbum({
							filePath: res.tempFilePath,
							success: function(res) {
								if (res.statusCode === 200) {
									uni.showToast({
										icon: "none",
										title: "保存成功"
									})
								}
							},
							fail: function(res) {}
						})
					},
					fail: function() {
						console.log('fail')
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.invite {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 20rpx;
	}

	.btn {
		bottom: 20rpx;
		text-align: center;
		background-color: #75D65E;
		padding: 26rpx 0;
		border-radius: 14rpx;
		width: 90%;
		margin-top: 50rpx;
	}
</style>